package com.label.web.controller.prototype;


import com.label.common.core.controller.BaseController;
import com.label.common.core.domain.AjaxResult;
import com.label.common.core.page.TableDataInfo;
import com.label.manager.domain.Task;
import com.label.manager.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/prototype/task")
public class TaskController extends BaseController {

    @Autowired
    private ITaskService taskService;

    /**
     * 查询任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Task task) {
        startPage();
        List<Task> list = taskService.selectTaskList(task);
        return getDataTable(list);
    }

    /**
     * 通过任务ID查询任务信息
     */
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable Long taskId) {
        return success(taskService.selectTaskById(taskId));
    }

    /**
     * 删除任务
     */
    @DeleteMapping("/{taskId}")
    public AjaxResult remove(@PathVariable Long taskId) {
        return toAjax(taskService.deleteTaskById(taskId));
    }

    /**
     * 新增任务
     */
    @PostMapping
    public AjaxResult add(@RequestBody Task task) {
        return toAjax(taskService.insertTask(task));
    }

    /**
     * 修改任务
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Task task) {
        return toAjax(taskService.updateTask(task));
    }
}
